<template>
    <div class="stbh">
        <!-- <div v-if="videoFlag"  style="width:100%;height:100%;background:black; opacity:0.3;z-index:999;"></div> -->
        <div id="mapDiv" class="mapDiv"></div>
        <el-dialog title="" :visible.sync="dialogTableVisible" style="z-index:99999;">
            <img :src="imgurl" alt="" style="width:100%;">
        </el-dialog>

        <div style="position: absolute;top:0; text-align:center;width:100%;background-color:rgba(3,3,3,0.3);">
            <div style="display:inline-block;width: 100%;padding:20px 0; text-align: center;color: white;font-size:26px;">
                <div>
                    {{titleName}}
                </div>
                <div style="position: absolute;right:27%;;top:30px;display:flex;align-items: center;">
                    <span style="font-size:16px;">全屏</span>
                    <i class="iconfont iconfullScreen" style="font-size:22px;margin-left:5px;" @click="fullScreen"></i>
                </div>
                <div style="position: absolute;right:22%;;top:30px;display:flex;align-items: center;">
                    <span style="font-size:16px;" @click="goback">退出登录</span>
                </div>
            </div>
        </div>
        <div class="zoology1">
            <div id="two" :class="[flag==1 ?'disActive':'active']" @click="gotrack">
                <div>
                    视频监控
                </div>
            </div>
            <div id="three" :class="[flag==2||flag==5||flag==7 ?'disActive':'active']" @click="farmarea">
                <div>
                    环境监测
                </div>
            </div>
            <div id="four" :class="[flag==3 ?'disActive':'active']" @click="weather">
                <div>
                    生产监管
                </div>
            </div>
            <div id="five" :class="[flag==4 ?'disActive':'active']" @click="camera">
                <div>
                    市场洞察
                </div>
            </div>
        </div>
        <div  v-if="videoFlag" style="width:800px;height:400px;background-color:rgba(0,0,0,0.5); opacity:1;z-index:9999;position:absolute;top:15%;left:30%;">
            <div  style="position: absolute;z-index:999; top:0%;left:0%;width:500px;height:400px;">
                <!-- <div  style="position: absolute;z-index:999; top:15%;left:35%;width:500px;height:400px;"> -->
                <video id="myPlayer"  controls playsInline webkit-playsinline style="width:500px;height:400px;">
                    <source ref="videoplay" :src="gdurl" type="application/x-mpegURL" />
                </video>
            </div>
            <div style="font-size:30px;position: absolute;top:-15px;right:-10px;" @click="closeVideo"><i class="el-icon-circle-close" style="color:white;"></i></div>
            <div  style="width:300px;height:400px;position:absolute;z-index:9999; top:20%;right:0%;">
                <div  style="width:500px;height:400px;relative:absolute;z-index:999; ">
                    <img src="./5.png" alt="" style="width:80px;position:absolute; z-index:999; top:1%;right:35%;cursor:pointer" @click="gotop">
                    <img src="./5.png" alt="" style="width:80px;transform:rotate(90deg);position:absolute; z-index:999; top:14%;right:18%;cursor:pointer" @click="goright">
                    <img src="./5.png" alt="" style="width:80px;transform:rotate(180deg);position:absolute; z-index:999; top:26%;right:35%;cursor:pointer" @click="gobottom">
                    <img src="./5.png" alt="" style="width:80px;transform:rotate(270deg);position:absolute; z-index:999; top:14%;right:52%;cursor:pointer" @click="goleft">

                    <img src="./fd.png" alt="" style="width:40px;position:absolute; z-index:999; top:40%;right:30%;cursor:pointer" @click="gosx">
                    <img src="./sx.png" alt="" style="width:40px;position:absolute; z-index:999; top:40%;right:53%;cursor:pointer" @click="gofd">
                </div>

            </div>
        </div>


        <!--   气象历史数据   -->
        <div v-if="meteorologicalFlag">
            <!--<div style="position: absolute;z-index:999; top:8%;left:18%;width:64vw;height:80vh;border:1px solid red;">
                <div>
                    <el-date-picker
                          v-model="value1"
                          type="datetimerange"
                        value-format="timestamp"
                        @change="abcd"
                          range-separator="至"
                          start-placeholder="开始日期"
                          end-placeholder="结束日期">
                    </el-date-picker>
                </div>

                <div style="font-size:30px;position: absolute;top:-15px;right:-15px;" @click="closeMeteorological"><i class="el-icon-circle-close" style="color:white;"></i></div>
            </div>-->
            <history-meteorological :qxData="meteorologicalDatas"  @closeMeteorologicals="closeMeteorological" @abcds="abcd"></history-meteorological>
        </div>


        <div class="left">
            <enterprise-list :enterpriseData="enterpriseLists" @change="changeOne" v-if="leftFlag == true"></enterprise-list>
        </div>

        <div v-if="flag == 4" style=" position: absolute;top:11vh;left: 23vw;color:white;background: #0076FF;padding:8px 5px;font-size:12px;border-radius:5px;"  @click="gotodataPanel">
            <span><i class="el-icon-folder-checked" style="font-size:14px;"></i></span>
            <span style="margin-left:5px;">数据看板</span>
        </div>


        <div class="right">
            <video-right :dataList="equipmentList"  v-if="flag == 1||flag==2 "></video-right>
            <!--<environment-right v-if="flag == 2"></environment-right>-->
            <production-right v-if="flag == 3"></production-right>
            <market-right v-if="flag == 4 "></market-right>
            <production-massif :dkData="productionMassifDatas" v-if="flag == 5"></production-massif>
            <environment-right :qixiangData="qixiangDataids" :equipmentData="equipmentDataAxios" @equipmentButtons="equipmentButtonsAxios"  v-if="flag == 7"></environment-right>
        </div>
        <data-panel v-if="flag == 6" :treeDatas="treeData" :treeDatasX="treeDataX" style="position: absolute;top:0;"></data-panel>

    </div>
</template>

<script>
import "./jquery.min.js"
import axios from 'axios'
import {company_findById } from "@/request/api.js"
import BaiduMap from '../../../common/js'
import marketRight from './marketRight.vue';
import enterpriseList from './enterpriseList.vue';
import videoRight from './videoRight.vue';
import productionRight from './productionRight.vue';
import environmentRight from './environmentRight.vue';
import productionMassif from './productionMassif.vue';
import historyMeteorological from './historyMeteorological.vue';
import dataPanel from './dataPanel.vue';
export default {
    data () {
        return {
            historyQxId: '',
            meteorologicalDatas: [],
            startTime: '',
            endTime: '',
            value1: [],
            titleName: '',
            treeData: [],
            treeDataX: [],
            flag: 1,
            equipmentList: [],
            qixiangDataid: {},
            qixiangDataids: {},
            equipmentDataAxios: [],
            videoFlag: false,
            leftFlag: true,
            meteorologicalFlag: false,
            enterpriseLists: [],
            productionMassifData: [],
            productionMassifDatas: [],
            dkDAta: [],
            allData: [],
            nongshiDatas:'',
            caishouDatas:[],
            principalId:'',
            peasantId:'',
            soilImg:'',
            name:'',
            area:'',
            lnglat:[{
                lng:'',
                lat:''
            }],
            polygonTool:'',
            zoom: '11',
            // points: [],
            line: '',
            T: '',
            lay: '',
            map: '',
            config: '',
            // iconMaker: [],
            dialog: false,
            dialogTableVisible: false,
            latitude:'',
            longtitude:"",
            form:{},
            list:'',
            urllist:"",
            geocoder:'',
            marker:'',
            lng:'',
            lat:'',
            polygon:'',
            markerTool:'',
            ruleForm:{
                type:'',
            },
            userList:[],
            mapList:[],
            baseList: [],
            imgurl: '',
            videourl: '',
            gdurl:'',
            getshujuUrl: '',
            accessToken:'',
            appKey:'',
            appSecret:'',
            serial:''
        }
    },
    components: {
        videoRight, //视频监控右侧组件
        environmentRight, //环境监测右侧组件
        productionRight, //生产监管右侧组件
        productionMassif, //生产监管右侧地块组件
        marketRight, // 市场观察右侧组件
        enterpriseList,  //左侧地块导航栏
        dataPanel,  //数据面板
        historyMeteorological,  //历史气象
    },
    created(){
    },
    mounted(){

        this.type = this.$route.query.type
        // if(this.$route.query.type) this.type = this.$route.query.type
        if(this.$route.query.id){
            var jsid = this.$route.query.id

            base_details(jsid).then((res) =>{
                this.ruleForm = res.data
            })
            this.dialog = this.$route.query.isshow
        }
        // this.getshuju()
        setTimeout(this.getshuju(),1000)
        this.init()
        this.init1()
    },
    methods:{
        gosx(){
            let data = {
                accessToken:this.accessToken,
                deviceSerial:this.serial,//设备序列号
                channelNo:'1',//通道号
                direction:'9',//方向
                speed:'1',//速度
            }
            var _this = this
            $.post("https://open.ys7.com/api/lapp/device/ptz/start",data,function(res){
                setTimeout(function () {
                    let data1 = {
                        accessToken:_this.accessToken,
                        deviceSerial:_this.serial,//设备序列号
                        channelNo:'1',//通道号
                        direction:'2',//方向
                        // speed:'1',//速度
                    }
                    $.post("https://open.ys7.com//api/lapp/device/ptz/stop",data1,function(res){
                    }).fail(function (xhr,errorText,errorType) {

                    })
                }, 1000);
            }).fail(function (xhr,errorText,errorType) {

            })
        },
        gofd(){
            let data = {
                accessToken:this.accessToken,
                deviceSerial:this.serial,//设备序列号
                channelNo:'1',//通道号
                direction:'8',//方向
                speed:'1',//速度
            }
            var _this = this
            $.post("https://open.ys7.com/api/lapp/device/ptz/start",data,function(res){
                setTimeout(function () {
                    let data1 = {
                        accessToken:_this.accessToken,
                        deviceSerial:_this.serial,//设备序列号
                        channelNo:'1',//通道号
                        direction:'2',//方向
                        // speed:'1',//速度
                    }
                    $.post("https://open.ys7.com//api/lapp/device/ptz/stop",data1,function(res){

                    }).fail(function (xhr,errorText,errorType) {

                    })
                }, 1000);
            }).fail(function (xhr,errorText,errorType) {

            })
        },
        gotop(){
            let data = {
                accessToken:this.accessToken,
                deviceSerial:this.serial,//设备序列号
                channelNo:'1',//通道号
                direction:'0',//方向
                speed:'1',//速度
            }
            var _this = this
            $.post("https://open.ys7.com/api/lapp/device/ptz/start",data,function(res){
                setTimeout(function () {
                    let data1 = {
                        accessToken:_this.accessToken,
                        deviceSerial:_this.serial,//设备序列号
                        channelNo:'1',//通道号
                        direction:'2',//方向
                        // speed:'1',//速度
                    }
                    $.post("https://open.ys7.com//api/lapp/device/ptz/stop",data1,function(res){

                    }).fail(function (xhr,errorText,errorType) {

                    })
                }, 1000);
            }).fail(function (xhr,errorText,errorType) {

            })
        },
        goleft(){
            // console.log(this.accessToken)
            let data = {
                accessToken:this.accessToken,
                deviceSerial:this.serial,//设备序列号
                channelNo:'1',//通道号
                direction:'2',//方向
                speed:'1',//速度
            }
            var _this = this
            $.post("https://open.ys7.com/api/lapp/device/ptz/start",data,function(res){
                setTimeout(function () {
                    let data1 = {
                        accessToken:_this.accessToken,
                        deviceSerial:_this.serial,//设备序列号
                        channelNo:'1',//通道号
                        direction:'2',//方向
                        // speed:'1',//速度
                    }
                    $.post("https://open.ys7.com//api/lapp/device/ptz/stop",data1,function(res){

                    }).fail(function (xhr,errorText,errorType) {

                    })
                }, 1000);
            }).fail(function (xhr,errorText,errorType) {

            })
        },
        gobottom(){
            let data = {
                accessToken:this.accessToken,
                deviceSerial:this.serial,//设备序列号
                channelNo:'1',//通道号
                direction:'1',//方向
                speed:'1',//速度
            }
            var _this = this
            $.post("https://open.ys7.com/api/lapp/device/ptz/start",data,function(res){
                setTimeout(function () {
                    let data1 = {
                        accessToken:_this.accessToken,
                        deviceSerial:_this.serial,//设备序列号
                        channelNo:'1',//通道号
                        direction:'2',//方向
                        // speed:'1',//速度
                    }
                    $.post("https://open.ys7.com//api/lapp/device/ptz/stop",data1,function(res){

                    }).fail(function (xhr,errorText,errorType) {

                    })
                }, 1000);
            }).fail(function (xhr,errorText,errorType) {

            })
        },
        goright(){
            let data = {
                accessToken:this.accessToken,
                deviceSerial:this.serial,//设备序列号
                channelNo:'1',//通道号
                direction:'3',//方向
                speed:'1',//速度
            }
            var _this = this
            $.post("https://open.ys7.com/api/lapp/device/ptz/start",data,function(res){
                setTimeout(function () {
                    let data1 = {
                        accessToken:_this.accessToken,
                        deviceSerial:_this.serial,//设备序列号
                        channelNo:'1',//通道号
                        direction:'2',//方向
                        // speed:'1',//速度
                    }
                    $.post("https://open.ys7.com//api/lapp/device/ptz/stop",data1,function(res){
                        // var arr = res.data
                        //     var list =  arr[arr.length-1]
                        //     app.firsttime = list.createtime
                        //     // app.productImg = lis
                    }).fail(function (xhr,errorText,errorType) {

                    })
                }, 1000);
            }).fail(function (xhr,errorText,errorType) {

            })
        },




        abcd(e){
            this.startTime = e[0]
            this.endTime = e[1]
            this.meteorologicalData()
        },
        //气象历史数据
        meteorologicalData(){
            // let baseSoilIdss = "2c9d0ded78c553cd0178c90448020048"
            // axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/getHistoryData?startTime="+ this.startTime + "&endTime=" + this.endTime + "&equId=" + this.historyQxId).then((res) =>{
            axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/getHistoryData?startTime="+ this.startTime + "&endTime=" + this.endTime + "&equId=" + this.historyQxId).then((res) =>{
                this.meteorologicalDatas = res.data
            })
        },

        video(e){
            console.log(e)
            this.serial = e.serial
            this.appKey = e.appKey
            this.appSecret = e.appSecret
            if(e){
                this.videourl = e.rtspHd

            }else{
                this.videourl = 'https://hls01open.ys7.com/openlive/4cd828c7dbcb4a448835eebb51591748.m3u8'
            }

            let data = {
                appKey:e.appKey,
                appSecret:e.appSecret
            }
            var _this =this
            $.post("https://open.ys7.com/api/lapp/token/get",data,function(res){
                _this.accessToken = res.data.accessToken
            }).fail(function (xhr,errorText,errorType) {

            })
            this.$refs.videoplay.src = this.videourl
            setTimeout(function(){
                var player = new EZuikit.EZUIPlayer('myPlayer');
            },500)

        },
        videos(e){
            // console.log(e)
            this.$refs.videoplay.src = e
        },
        changeOne(data){
            var datas = JSON.parse(data.coordinate)
            var equipmentId = data.id
            this.map.panTo(new T.LngLat(datas[0].lng, datas[0].lat), 18);
            // axios.get("http://47.108.220.160:90/jcApi/plant//dockDevice/getEquByMassifId?massifId=" + equipmentId).then((res) =>{
            axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/getEquByMassifId?massifId=" + equipmentId + "&type=" + '气象传感').then((res) =>{
                this.equipmentDataAxios = res.data
            })
            this.flag = 7
        },
        //点击全屏
        fullScreen(){
            let element = document.documentElement;
            if (this.fullscreen) {
                if (document.exitFullscreen) {
                    document.exitFullscreen();
                } else if (document.webkitCancelFullScreen) {
                    document.webkitCancelFullScreen();
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                } else if (document.msExitFullscreen) {
                    document.msExitFullscreen();
                }
            } else {
                if (element.requestFullscreen) {
                    element.requestFullscreen();
                } else if (element.webkitRequestFullScreen) {
                    element.webkitRequestFullScreen();
                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen();
                } else if (element.msRequestFullscreen) {
                    // IE11
                    element.msRequestFullscreen();
                }
            }
            this.fullscreen = !this.fullscreen;
        },
        //视频监控
        gotrack(){
            this.equipmentList = []
            for(let c=0;c<this.allData.length;c++){
                if(this.allData[c].type == 7){
                    //摄像头设备列表
                    this.equipmentList.push(this.allData[c])
                }
            }
            this.flag = 1
            this.leftFlag = true
            // this.$router.push({
            // 	path:'/yzdigtalMap/trackmap',
            // })
        },
        init(){
            // datacenter_initjg("").then((res) =>{

            // })
        },
        goback(){
            let s = localStorage.getItem("zh_type")
            if(s== "GOV"){
                localStorage.setItem("requestUrl","http://47.108.220.160:90/jcApi/plant/control/")
            }else{
                localStorage.setItem("requestUrl","http://47.108.220.160:90/jcApi/plant/")
            }

            this.$router.go(-1)
            // player.stop();

        },
        equipmentButtonsAxios(data){
            this.qixiangDataid = {}
            // 气象传感数据
            let baseSoilId = data.baseSoilId
            var _this = this
            // let baseSoilId = "2c9d0ded78c553cd0178c912e47f0053"
            // axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/getNowData?baseSoilId=" + baseSoilId).then((res) =>{
            axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/getNowData?baseSoilId=" + baseSoilId).then((res) =>{
                var qixiangDatas = res.data.data

                for(let r = 0;r<qixiangDatas.length;r++){
                    if(qixiangDatas[r].ename == "风速"){
                        _this.qixiangDataid.windspeed =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "大气温度"){
                        _this.qixiangDataid.atmosphericTemperature =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "空气温度"){
                        _this.qixiangDataid.atmosphericTemperature =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "数字气压"){
                        _this.qixiangDataid.digitalAirPressure =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "大气压"){
                        _this.qixiangDataid.digitalAirPressure =qixiangDatas[r].evalue + qixiangDatas[r].eunit

                    }
                    if(qixiangDatas[r].ename == "风向"){
                        _this.qixiangDataid.windDirection =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "土壤温度"){
                        _this.qixiangDataid.soil =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "土壤湿度"){
                        _this.qixiangDataid.humidity =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "大气湿度"){
                        _this.qixiangDataid.atmosphericHumidity =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "太阳总辐射"){
                        _this.qixiangDataid.totalSolarRadiation =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "辐射累计"){
                        _this.qixiangDataid.radiationAccumulation =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "雨量"){
                        _this.qixiangDataid.rainfall =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "降雨量"){
                        _this.qixiangDataid.rainfall1 =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "雨量累计"){
                        _this.qixiangDataid.accumulatedRainfall =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "二氧化碳"){
                        _this.qixiangDataid.Co2 =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "电导率"){
                        _this.qixiangDataid.conductivity =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }

                    if(qixiangDatas[r].ename == "pH值"){
                        _this.qixiangDataid.PHvalue =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                    if(qixiangDatas[r].ename == "土壤PH值"){
                        _this.qixiangDataid.PHvalue =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                    }
                  if(qixiangDatas[r].ename == "照度"){
                    _this.qixiangDataid.Luxvalue =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                  }
                }
                // console.log(this.qixiangDataid)
                this.qixiangDataids = this.qixiangDataid
            })
        },
        //环境监测
        farmarea(){
            this.equipmentList = []
            for(let c=0;c<this.allData.length;c++){
                if(this.allData[c].type == 6){
                    //气象设备列表
                    this.equipmentList.push(this.allData[c])
                }

            }
            this.flag = 2
            this.leftFlag = true
        },
        // 生产监管
        weather(){
            this.flag = 3
            this.leftFlag = true
        },
        //市场洞察
        camera(){
            this.flag = 4
            this.leftFlag = true
        },
        //关闭视频
        closeVideo(){
            this.videoFlag = false
            this.leftFlag = true
            this.gdurl = ''
            this.$refs.videoplay.src = ""
        },
        //关闭历史气象数据
        closeMeteorological(){
            this.meteorologicalFlag = false
        },
        //数据面板
        gotodataPanel(){
            this.flag = 6
            this.leftFlag = false
        },
        getshuju(){
            // datacenter_initjg("").then((res)=>{
            if(this.$util.get("userInfo").userInfo.userType == "GOV"){
                this.dataplane = true
                this.getshujuUrl = "http://47.108.220.160:90/jcApi/plant/basesoil/initjg"
            }else{
                this.getshujuUrl = "http://47.108.220.160:90/jcApi/plant/basesoil/initjgPlant"
            }
            axios.get(this.getshujuUrl).then((res) =>{
                // axios.get("http://47.108.220.160:90/jcApi/plant/basesoil/initjgPlant").then((res) =>{
                this.enterpriseLists = res.data
                var arr1 = []

                for(var a = 0; a<this.enterpriseLists.length;a++){
                    if((this.enterpriseLists[a].basesoildViews).length>0){

                        // //开始    别问我为啥这样写  我也不知道
                        arr1 = this.enterpriseLists[a].basesoildViews
                        var arr2 = []
                        for(var i=0;i<arr1.length;i++){

                            if(arr1[i].type ==2 || arr1[i].type == 3){
                                arr2.push(arr1[i])
                            }

                            this.enterpriseLists[a].arr2 = arr2
                            // console.log(this.enterpriseLists[a].basesoildViews)
                        }
                        // // 结束
                        for(var b = 0;b<this.enterpriseLists[a].arr2.length;b++){
                            this.enterpriseLists[a].arr2[b].abbreviation = this.enterpriseLists[a].arr2[b].name
                        }
                    }
                }
                let initjgData = res.data

                for(let a=0;a<initjgData.length;a++){
                    if(initjgData[a].basesoildViews.length>0){
                        for(let b=0;b<initjgData[a].basesoildViews.length;b++){
                            this.allData.push(initjgData[a].basesoildViews[b])
                        }
                    }
                }
                // console.log(allData)
                let dkData = []
                for(let c=0;c<this.allData.length;c++){
                    if(this.allData[c].type == 1 || this.allData[c].type == 2 || this.allData[c].type == 3 || this.allData[c].type == 4){
                        dkData.push(this.allData[c])
                    }
                    if(this.allData[c].type == 7){
                        //摄像头设备列表
                        this.equipmentList.push(this.allData[c])
                    }

                    if(this.allData[c].type == 1){
                        // console.log(allData[c])
                        // console.log()
                        var latlng = JSON.parse(this.allData[c].coordinate)
                        this.latitude = latlng[0].lat
                        this.longtitude = latlng[0].lng
                    }
                }

                // this.mapList = res.data[3].basesoildViews
                if(this.mapList.length>0){
                    var coorlist = JSON.parse(res.data[3].basesoildViews[0].coordinate)
                    var arr=[]
                    for(var j=0;j<coorlist.length;j++){
                        var s = coorlist[j]
                        arr.push(new T.LngLat(parseFloat(s.lng), parseFloat(s.lat)))
                    }
                    this.urllist = arr
                    for (let i = 0; i < this.mapList.length; i++) {
                        var list = [];
                        var newList = [];
                        var list = this.mapList[0].coordinate.split(";");
                        // console.log(list)
                        if(this.mapList[i].type == 1){
                            this.baseList.push(this.mapList[i])
                        }

                        for(var j = 0 ; j< list.length;j++){
                            newList = JSON.parse(list[j])
                            this.longtitude = parseFloat(newList[0].lng)
                            this.latitude = parseFloat(newList[0].lat)
                        }
                    }

                }
                this.mapList = this.allData


                BaiduMap.init()
                    .then((T) => {
                        this.T = T
                        // console.log(T)
                        this.zoom = 14
                        // this.latitude = localStorage.getItem("latitude")
                        this.map = new T.Map('mapDiv')// 初始化地图对象
                        this.map.centerAndZoom(new T.LngLat(this.longtitude,this.latitude), 17)// 设置显示地图的中心点和级别
                        this.map.disableDoubleClickZoom()
                        //创建对象
                        // var ctrl = new T.Control.MapType();
                        //添加控件
                        this.map.addControl(TMAP_HYBRID_MAP);
                        // 创建图片对象
                        var config = {
                            strokeColor:"blue", //折线颜色  s
                            fillColor:"blue",    //填充颜色。当参数为空时，折线覆盖物将没有填充效果
                            strokeWeight:"3px", //折线的宽度，以像素为单位
                            strokeOpacity:0.5,  //折线的透明度，取值范围0 - 1
                            fillOpacity:0.5, //填充的透明度，取值范围0 - 1
                            showLabel:true  //是否显示页面，默认为true
                        };
                        this.markerTool = new T.MarkTool(this.map,icon)
                        this.polygonTool = new T.PolygonTool(this.map,config);
                        this.geocoder = new T.Geocoder(this.map)

                        //注册测面工具绘制完成后的事件
                        // type  undefined
                        for(var k=0;k<this.mapList.length;k++){
                            if(this.mapList[k].type == 1 || this.mapList[k].type == 2 || this.mapList[k].type == 3){
                                var con = JSON.parse(this.mapList[k].coordinate)
                                this.polygon = new T.Polygon(con, { color: this.mapList[k].color,fillOpacity:this.mapList[k].diaphaneity / 100,details:this.mapList[k] })
                                this.map.addOverLay(this.polygon)

                                var name = this.mapList[k]
                                var _this = this
                                this.polygon.addEventListener("click",function huoqu(e){
                                    // var _this = this
                                    // _this.details = e.target.options.details
                                })
                                //双击事件
                                this.polygon.addEventListener("dblclick",function handleEdit(e){
                                    // _this.ruleForm = e.target.options.details
                                    // _this.peasantId = _this.ruleForm.peasantName
                                    // _this.principalId = _this.ruleForm.principalName
                                    localStorage.setItem("list",_this.ruleForm.coordinate)

                                    // _this.ruleForm.diaphaneity = Number(_this.ruleForm.diaphaneity)
                                    // _this.dialog = true
                                    _this.flag = 5
                                    _this.productionMassifData = []
                                    _this.productionMassifData = e.target.options.details
                                    var id = _this.productionMassifData.companyId
                                  axios.get("http://47.108.220.160:90/jcApi/plant/company/findById/" + id).then((res) =>{
                                    // this.titleName = res.data.data.name
                                  // })
                                    // company_findById(id).then((res) =>{
                                        _this.productionMassifData.qyName=res.data.data.abbreviation

                                        //地块数据回显
                                        let data = {
                                            soil:_this.productionMassifData.id
                                        }
                                        // axios.post("http://192.168.0.148:8880/plant/plant/soil",data).then((res) =>{
                                        axios.post("http://47.108.220.160:90/jcApi/plant/plant/soil",data).then((res) =>{
                                            _this.dkDAta = res.data.data
                                            for(let a=0;a<_this.dkDAta.length;a++){
                                                // get(a,_this.dkDAta)
                                                var nongshiData ={
                                                    plantId: _this.dkDAta[a].id
                                                }
                                                //地块农事记录
                                                // axios.post("http://192.168.0.148:8880/plant/farm/type",nongshiData).then((res) =>{
                                                axios.post("http://47.108.220.160:90/jcApi/plant/farm/type",nongshiData).then((res) =>{
                                                    _this.dkDAta[a].nongshi = res.data.data
                                                })
                                                var caishouData = {
                                                    plantBatch: _this.dkDAta[a].batch
                                                }
                                                //地块采收记录
                                                // axios.post("http://192.168.0.148:8880/plant/reap/plantBatch",caishouData).then((res) =>{
                                                axios.post("http://47.108.220.160:90/jcApi/plant/reap/plantBatch",caishouData).then((res) =>{
                                                    _this.dkDAta[a].caishouNumber = res.data.data[0]
                                                    _this.dkDAta[a].caishouWeight = res.data.data[1]
                                                })
                                            }
                                            _this.productionMassifData.plantDAta = _this.dkDAta
                                            _this.productionMassifDatas = _this.productionMassifData
                                        })
                                    })
                                })
                            }
                            //摄像头
                            if(this.mapList[k].type == 7){
                                var con = JSON.parse(this.mapList[k].coordinate)
                                var icon = new T.Icon({
                                    iconUrl: 'https://grove.cpzsyun.com:81/re/c.png',
                                    iconSize: new T.Point(19, 27),
                                    iconAnchor: new T.Point(10, 25)
                                })
                                this.marker = new T.Marker(con,{icon:icon,details:this.mapList[k]})
                                // console.log(this.marker)
                                this.map.addOverLay(this.marker)
                                let _this = this
                                this.marker.addEventListener("click",function huoqu(e){
                                    // _this.ruleForm = e.target.options.details
                                    // _this.dialog = true
                                    // console.log(111)
                                    //  _this.dialogTableVisible = true
                                    //  _this.imgurl = _this.$store.state.imageUrls +  e.target.options.details.soilImg
                                    // console.log(_this.dialogTableVisible)
                                })
                                this.marker.addEventListener("dblclick",function huoqu(e){
                                    _this.ruleForm = e.target.options.details
                                    _this.videoFlag = true
                                    // console.log(e)
                                    // var id = "2c9d0ded78c553cd0178c8eeaa000034"
                                    var id = e.target.options.details.id
                                    axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/getUrl?baseSoilId=" + id).then((res) =>{
                                        // console.log(res)
                                        // if(res.data.data[0]){
                                        // 	_this.videourl = res.data.data[0].rtspHd
                                        // }else{
                                        // 	_this.videourl = 'https://hls01open.ys7.com/openlive/4cd828c7dbcb4a448835eebb51591748.m3u8'
                                        // }
                                        // console.log(_this.videourl)
                                        _this.video(res.data.data[0])
                                    })

                                })
                            }
                            //气象传感
                            if(this.mapList[k].type == 6){
                                var con = JSON.parse(this.mapList[k].coordinate)
                                var icon = new T.Icon({
                                    // iconUrl: 'http://39.96.59.234:8884/re/a.png',
                                    iconUrl: 'https://grove.cpzsyun.com:81/re/a.png',
                                    iconSize: new T.Point(19, 27),
                                    iconAnchor: new T.Point(10, 25)
                                })
                                this.marker = new T.Marker(con,{icon:icon,details:this.mapList[k]})
                                this.map.addOverLay(this.marker)
                                let _this = this
                                this.marker.addEventListener("click",function huoqu(e){
                                    // _this.ruleForm = e.target.options.details
                                    // _this.dialog = true
                                    // console.log(111)
                                    //  _this.dialogTableVisible = true
                                    //  _this.imgurl = _this.$store.state.imageUrls +  e.target.options.details.soilImg
                                    // console.log(_this.dialogTableVisible)
                                })
                                this.marker.addEventListener("dblclick",function huoqu(e){
                                    _this.flag = 7
                                    _this.meteorologicalFlag = true
                                    _this.qixiangDataid = {}
                                    //气象传感数据
                                    let baseSoilId = e.target.options.details.id
                                    // let baseSoilIdss = "2c9d0ded78c553cd0178c90448020048"
                                    _this.historyQxId = e.target.options.details.soilEquipments[0].equipmentId
                                    console.log(e.target.options.details.soilEquipments[0].equipmentId)
                                    axios.get("http://47.108.220.160:90/jcApi/plant//dockDevice/getHistoryData?equId=" + _this.historyQxId).then((res) =>{
                                        // axios.get("http://47.108.220.160:90/jcApi/plant//dockDevice/getHistoryData?equId=" + _this.historyQxId).then((res) =>{
                                        _this.meteorologicalDatas = res.data
                                        console.log(_this.meteorologicalDatas)
                                    })
                                    // let baseSoilId = "2c9d0ded78c553cd0178c91861890063"
                                    // axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/getNowData?baseSoilId=" + baseSoilId).then((res) =>{
                                    axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/getNowData?baseSoilId=" + baseSoilId).then((res) =>{
                                        // axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/findList3Days?baseSoilId=" + baseSoilId).then((res) =>{
                                        // axios.get("http://47.108.220.160:90/jcApi/plant/dockDevice/findList3Days?baseSoilId=" + baseSoilId).then((res) =>{

                                        var qixiangDatas = res.data.data
                                        // console.log(qixiangDatas)
                                        for(let r = 0;r<qixiangDatas.length;r++){
                                            if(qixiangDatas[r].ename == "风速"){
                                                _this.qixiangDataid.windspeed =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "大气温度"){
                                                _this.qixiangDataid.atmosphericTemperature =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "空气温度"){
                                                _this.qixiangDataid.atmosphericTemperature =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "数字气压"){
                                                _this.qixiangDataid.digitalAirPressure =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "大气压"){
                                                _this.qixiangDataid.digitalAirPressure =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "风向"){
                                                _this.qixiangDataid.windDirection =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "土壤温度"){
                                                _this.qixiangDataid.soil =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "土壤湿度"){
                                                _this.qixiangDataid.humidity =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "大气湿度"){
                                                _this.qixiangDataid.atmosphericHumidity =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "太阳总辐射"){
                                                _this.qixiangDataid.totalSolarRadiation =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "辐射累计"){
                                                _this.qixiangDataid.radiationAccumulation =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "雨量"){
                                                _this.qixiangDataid.rainfall =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "降雨量"){
                                                _this.qixiangDataid.rainfall1 =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "雨量累计"){
                                                _this.qixiangDataid.accumulatedRainfall =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "二氧化碳"){
                                                _this.qixiangDataid.Co2 =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "电导率"){
                                                _this.qixiangDataid.conductivity =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }

                                            if(qixiangDatas[r].ename == "pH值"){
                                                _this.qixiangDataid.PHvalue =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                            if(qixiangDatas[r].ename == "土壤PH值"){
                                                _this.qixiangDataid.PHvalue =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                            }
                                          if(qixiangDatas[r].ename == "照度"){
                                            _this.qixiangDataid.Luxvalue =qixiangDatas[r].evalue + qixiangDatas[r].eunit
                                          }
                                        }
                                        _this.qixiangDataids = _this.qixiangDataid
                                    })
                                    // _this.ruleForm = e.target.options.details

                                })
                            }
                            //  this.map.addOverLay(this.marker)
                        }
                    })
            })

        },
        init1(){
            //扫码分布
            // axios.post("http://192.168.0.148:8880/plant/box/scan").then((res) =>{
            axios.post("http://47.108.220.160:90/jcApi/plant/box/scan").then((res) =>{
                var yieldData = res.data.data
                var keys=[];
                var values=[];
                var objs = yieldData
                for(var key in objs){
                    keys.push(key);
                    values.push(objs[key]);
                }
                let arr3=[]
                for(var a=0;a<keys.length;a++){
                    var object = {}
                    object.id = keys[a]
                    object.number = values[a]
                    arr3.push(object)
                }
                let arr4 = arr3.sort(function(a,b){
                    return b.number-a.number
                })
                let arr5 = arr4.slice(0,10)
                for(let b= 0;b<arr5.length;b++){
                    var id = arr3[b].id
                    this.treeData.push(arr3[b].number)
                  axios.get("http://47.108.220.160:90/jcApi/plant/company/findById/" + id).then((res) =>{
                    // company_findById(id).then((res) =>{
                        let data = res.data.data.name
                        this.treeDataX.push(data)
                    })
                }
            })
            var id = localStorage.getItem("companyId")
            // company_findById(id).then((res)=>{
            axios.get("http://47.108.220.160:90/jcApi/plant/company/findById/" + id).then((res) =>{
                this.titleName = res.data.data.name
            })
        },
    },

}
</script>

<style scoped lang="less">
.el-scrollbar__wrap {
    overflow-x: hidden;
}
.mapDiv{
    width: 100%;
    height: 100vh;
    z-index:0;
}
.zoology{
    width:100px;
    text-align:center;
    height:60px;
    line-height:30px;
    position: absolute;
    bottom: 100px;
    left: 40px;
    z-index: 100;
    background:white;
    border-radius:6px;
}
.zoology1{
    width: 100%;
    text-align:center;
    height:40px;
    line-height:40px;
    position: absolute;
    bottom: 60px;
    z-index: 100;
    border-radius:6px;
}
.stbh{
    position:relative;
    width: 100%;
    height: 100%;
}
.left{
    position: absolute;
    top:0;
    left: 0;
}
.right{
    position: absolute;
    top:0;
    right: 0;
}
.disActive{
    display:inline-block;
    width: 80px;
    font-size:14px;
    margin-right: 20px;
    text-align: center;
    background:#0076FF;
    border-radius: 6px;
    color: white;
}
.active{
    display:inline-block;
    width: 80px;
    font-size:14px;
    margin-right: 20px;
    text-align: center;
    color: #0076FF;
    background-color:rgba(3,3,3,0.3);
    border-radius: 6px;
}

</style>
